//
//  MemberChangeEmailController.m
//  yameishe3
//
//  Created by pro on 2017/3/2.
//  Copyright © 2017年 yameishe. All rights reserved.
//

#import "MemberChangeEmailController.h"
#import "YMSMemberManager.h"
@interface MemberChangeEmailController ()
@property(weak, nonatomic)IBOutlet UITextField *accountTF;
@property(weak, nonatomic)IBOutlet UITextField *emailTF;
@property(weak, nonatomic)IBOutlet UITextField *codeTF;
@property(weak, nonatomic)IBOutlet UIButton *functionBtn;
@end

@implementation MemberChangeEmailController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(void)viewWillDisappear:(BOOL)animated {
    // 反注册键盘
    [super viewWillDisappear:YES];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction)onTouchFunctionBtn:(id)sender
{
    if ([self checkFunctionState]==NO) {
        return;
    }
    YMSMember *member = [YMSMember loginMember];
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setValue:member.token forKey:@"_token"];
    [dic setValue:_codeTF.text forKey:@"user_code"];
    [dic setValue:_emailTF.text forKey:@"user_Eail"];
    [dic setValue:@"update_email" forKey:@"type"];
    [[YMSMemberManager alloc]MemberUpdateInfoWithDic:dic successBlock:^(NSDictionary *result) {
        [self.navigationController popViewControllerAnimated:YES];
    } failureBlock:^(NSString *error) {
        
    }];

}

-(BOOL)checkFunctionState
{
//    if (!_accountTF.text.length) {
//        NSLog(@"");
//        return NO;
//    }
    if (!_emailTF.text.length) {
        NSLog(@"");
        return NO;
    }
    if (!_codeTF.text.length) {
        NSLog(@"");
        return NO;
    }
    return YES;
}

-(IBAction)onTouchCodeBtn:(id)sender
{
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setValue:[YMSMember loginMember].username forKey:@"username"];
    [dic setValue:_emailTF.text forKey:@"user_email"];
    [dic setValue:@"find_pass" forKey:@"type"];
    [dic setValue:[YMSMember loginMember].token forKey:@"_token"];
    [[YMSMemberManager alloc]getEmailCodeWithDic:dic successBlock:^(NSDictionary *result) {
    
    } failureBlock:^(NSString *error) {
    
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
